/**
 * @author : cyb1010
 * @date   : 2024-12-04 08:30:37
 * @file   : kte.cpp
 */
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
const int N = 400010;
int __, _, n;
ull op[N];
vector<ull> buc;
bool in[N];
struct SGT {
    int cnt, tgp;
    ull sum, prs;
} t[N << 2];
void add_t(int p, int x) { t[p].tgp += x, t[p].prs += t[p].sum * x; }
void psd(int p) {
    add_t(p << 1, t[p].tgp), add_t(p << 1 | 1, t[p].tgp), t[p].tgp = 0;
}
void psu(int p) {
    t[p].cnt = t[p << 1].cnt + t[p << 1 | 1].cnt;
    t[p].sum = t[p << 1].sum + t[p << 1 | 1].sum;
    t[p].prs = t[p << 1].prs + t[p << 1 | 1].prs;
}
void add_tgp(int p, int l, int r, int le, int x) {
    if (r < le) return;
    if (l >= le) return add_t(p, x), void();
    int mid = l + r >> 1;
    psd(p), add_tgp(p << 1, l, mid, le, x);
    add_tgp(p << 1 | 1, mid + 1, r, le, x), psu(p);
}
void ins(int p, int l, int r, int k) {
    if (l == r)
        return t[p].cnt = 1, t[p].sum = buc[k - 1],
               t[p].prs = t[p].sum * t[p].tgp, void();
    int mid = l + r >> 1;
    psd(p);
    k <= mid ? ins(p << 1, l, mid, k) : ins(p << 1 | 1, mid + 1, r, k);
    psu(p);
}
void del(int p, int l, int r, int k) {
    if (l == r) return t[p].cnt = t[p].sum = t[p].prs = 0, void();
    int mid = l + r >> 1;
    psd(p);
    k <= mid ? del(p << 1, l, mid, k) : del(p << 1 | 1, mid + 1, r, k);
    psu(p);
}
void chg(ull x) {
    int id = upper_bound(ALL(buc), x) - buc.begin();
    if (in[id])
        in[id] = 0, del(1, 1, n, id), add_tgp(1, 1, n, id, -1);
    else
        in[id] = 1, ins(1, 1, n, id), add_tgp(1, 1, n, id, 1);
}
ull ql(int p, int l, int r, int k) {
    if (k >= t[p].cnt) return t[p].sum;
    if (!k) return 0;
    int mid = l + r >> 1;
    if (t[p << 1].cnt >= k) return ql(p << 1, l, mid, k);
    return t[p << 1].sum + ql(p << 1 | 1, mid + 1, r, k - t[p << 1].cnt);
}
ull qr(int p, int l, int r, int k) {
    if (k >= t[p].cnt) return t[p].sum;
    if (!k) return 0;
    int mid = l + r >> 1;
    if (t[p << 1 | 1].cnt >= k) return qr(p << 1 | 1, mid + 1, r, k);
    return t[p << 1 | 1].sum + qr(p << 1, l, mid, k - t[p << 1 | 1].cnt);
}
ull qprs(int p, int l, int r, int k) {
    if (k >= t[p].cnt) return t[p].prs;
    if (!k) return 0;
    int mid = l + r >> 1;
    psd(p);
    if (t[p << 1].cnt >= k) return qprs(p << 1, l, mid, k);
    return t[p << 1].prs + qprs(p << 1 | 1, mid + 1, r, k - t[p << 1].cnt);
}

ull qpre(int x) { return ql(1, 1, n, x) * (x + 1) - qprs(1, 1, n, x); }
ull qpre(int l, int r) { return qpre(r) - qpre(l - 1); }
ull qsuf(int x) {
    return t[1].prs - qprs(1, 1, n, t[1].cnt - x)
           - qr(1, 1, n, x) * (t[1].cnt - x);
}
ull qsuf(int l, int r) { return qsuf(r) - qsuf(l - 1); }

int main() {
    fo("kte");
    cin.tie(0)->sync_with_stdio(0);
    cin >> _;
    for (int i = 1; i <= _; i++) cin >> op[i], buc.push_back(op[i]);
    sort(ALL(buc)), buc.erase(unique(ALL(buc)), buc.end()), n = SZ(buc);
    for (int i = 1; i <= _; i++) {
        chg(op[i]);
        if (!t[1].cnt) {
            cout << "0\n";
            continue;
        }
        const int D = (t[1].cnt + 1) / 2;
        if (ql(1, 1, n, D) >= qr(1, 1, n, D - 1)) {
            cout << t[1].prs * 2 - t[1].sum * (t[1].cnt + 1) << '\n';
            continue;
        }
        int l = 1, r = D, mid;
        while (l < r) {
            mid = l + r >> 1;
            if (ql(1, 1, n, mid) >= qr(1, 1, n, mid - 1))
                l = mid + 1;
            else
                r = mid;
        }
        int posl = l;
        r = t[1].cnt;
        while (l < r) {
            mid = l + r >> 1;
            if (ql(1, 1, n, mid) >= qr(1, 1, n, mid - 1))
                r = mid;
            else
                l = mid + 1;
        }
        cout << t[1].prs - qpre(1, posl - 1) - qpre(l, t[1].cnt)
                    - qsuf(posl - 1, l - 2)
             << '\n';
    }
    // cerr << clock() << endl;
    return 0 ^ __ ^ 0;
}